package com.hxl.aop;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.hxl.aop.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Aop测试启动类
 *
 * @author 霍帅帅
 * @since 2024-06-11 23:06
 */
@SpringBootApplication
public class AopTestApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext app = SpringApplication.run(AopTestApplication.class, args);
        SpringUtil.setApplicationContext(app);
//        Fruit apple = app.getBean(Apple.class);
//        Fruit orange = app.getBean(Orange.class);
//        apple.eat();
//        orange.eat();
//        System.out.println("apple: " + apple.getClass().getName());
//        System.out.println("orange: " + orange.getClass().getName());
    }

}


//整合数据库生成文档工具，初始化生成数据库文档
/*  implements ApplicationRunner {

        @Autowired
        ApplicationContext applicationContext;

        public static void main(String[] args) {
            SpringApplication.run(AopTestApplication.class, args);
        }

        @Bean(name = "myDataSource")
        @Qualifier("myDataSource")
        @ConfigurationProperties(prefix="biz")
        public DataSource getMyDataSource(){
            return DataSourceBuilder.create().build();
        }

        @Resource(name = "myDataSource")
        private DataSource myDataSource;

        @Override
        public void run(ApplicationArguments args) throws Exception {

//        DruidDataSource dataSourceMysql = applicationContext.getBean(DruidDataSource.class);

            //模板引擎配置 生成文件配置
            EngineConfig engineConfig = EngineConfig.builder()
                    // 生成文件路径
                    .fileOutputDir("D://tmp/")
                    // 打开目录
                    .openOutputDir(false)
                    // 文件类型
                    .fileType(EngineFileType.WORD)
                    // 生成模板实现
                    .produceType(EngineTemplateType.freemarker).build();

            // 生成文档配置（包含以下自定义版本号、描述等配置连接），文档名称拼接：数据库名_描述_版本.扩展名
            Configuration config = Configuration.builder()
                    .title("数据库文档")
                    // 版本号
                    .version("1.0.0")
                    // 描述
                    .description("数据库设计文档")
                    // 数据源
                    .dataSource(myDataSource)
                    // 模板引擎配置
                    .engineConfig(engineConfig)
                    // 加载配置：想要生成的表、想要忽略的表
                    .produceConfig(getProcessConfig())
                    .build();
            // 执行生成
            new DocumentationExecute(config).execute();
        }

        *//**
 * 配置想要生成的表+ 配置想要忽略的表
 *
 * @return 生成表配置
 *//*
        public static ProcessConfig getProcessConfig() {
            // 忽略表名
            List<String> ignoreTableName = Arrays.asList("");

            return ProcessConfig.builder()
                    //根据名称指定表生成
                    .designatedTableName(new ArrayList<>())
                    //根据表前缀生成
                    .designatedTablePrefix(new ArrayList<>())
                    //根据表后缀生成
                    .designatedTableSuffix(new ArrayList<>())
                    //忽略表名
                    .ignoreTableName(ignoreTableName)
                    .build();
        }

    }*/
